﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:CustomTextBox.Controls"
    xmlns:converters="clr-namespace:CustomTextBox.Converters">

    <converters:ObjectToVisibilityConverter x:Key="ObjectToVisibilityConverter"/>

    <Style TargetType="controls:PhoneTextBox">
        <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:PhoneTextBox">
                    <Border Background="{TemplateBinding Background}" CornerRadius="5" Margin="{StaticResource PhoneTouchTargetOverhang}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Disabled"/>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused"/>
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid Margin="6">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Image Margin="6" Source="{TemplateBinding ImageSource}" Width="32" Height="32" VerticalAlignment="Center" Visibility="{Binding ImageSource, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource ObjectToVisibilityConverter}}"/>
                            <TextBlock Margin="6" x:Name="HintTextBlock" Grid.Column="1" Text="{TemplateBinding Hint}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" Opacity="0.54" />
                            <TextBox Margin="6" x:Name="ControlTextBox" Grid.Column="1" Text="{Binding Value, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}" Foreground="{TemplateBinding Foreground}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" >
                                <TextBox.Template>
                                    <ControlTemplate TargetType="TextBox">
                                        <ContentControl x:Name="ContentElement" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" />
                                    </ControlTemplate> 
                                </TextBox.Template>
                            </TextBox>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>